/**
 * Created by JetBrains PhpStorm.
 * User: Xnfy520@gmail.com
 * Date: 12-3-11
 * Time: 下午11:10
 */
$(function(){

        $("#article-index form.select").submit(function(){
            var key = $("#article-index input[name=key]").val();
            if(key==''){
                alert('搜索文章不能为空');
                return false;
            }
        });

        $("#article-index a.delete").click(function(){
            var datas = $("#article-index form.delete").serializeArray();
            if(datas==''){
                alert('请选择要删除的文章');
            }else{
                if(window.confirm('确认删除这些文章?')){
                    $("#article-index form.delete").submit();
                }
            }
        });


    $("#article-select form.select").submit(function(){
        var key = $("#article-select input[name=key]").val();
        if(key==''){
            alert('搜索文章不能为空');
            return false;
        }
    });

    $("#article-select form.getname").submit(function(){
        var key = $("#article-select input[name=getname]").val();
        if(key==''){
            alert('请选择选择文章');
            return false;
        }
    });

    $("#article-select tbody tr").click(function(){
        var name = $(this).find(".name").html();
        var id = $(this).find(":radio").val();
        $(this).find(":radio").attr("checked", "checked");
        $("#article-select form.getname input[name=getname]").val(name);
        $("#article-select form.getname input[name=sid]").val(id);
    });

    $("#article-select tbody tr").hover(function(){
        $(this).css("background-color", "white");
    }, function(){
        $(this).css("background-color", "#EFF3F6");
    });


    $("#article-select .title .back").click(function(){
        window.history.go(-1);
    });

    $("#article-index a.select").toggle(function(){
        $("#article-index input[type=checkbox]").attr('checked', 'checked');
    },function(){
        $("#article-index input[type=checkbox]").attr('checked',null);
    });

    $("#article-add input.submit").click(function(){
        var sid = $("#article-add select.sectionid :selected").val();
        var cid = $("#article-add select.categoryid :selected").val();
        if(sid==0){
            alert('请选择所属单元');
            return false;
        }else if(cid==0){
            alert('请选择所属分类');
            return false;
        }
    });

    $("#article-add select.sectionid").change(function(){
        var sid = $("#article-add select.sectionid :selected").val();
        $.post(APP+'/Article/returns', {id: sid}, function(data){
            var obj = JSON.parse(data);
            var category = $("#article-add select.categoryid");
            category.html("");
            $('<option value="0">---请选择所属分类---</option>').appendTo(category);
            for(var i=0; i<obj.length; i++){
                $('<option value="'+obj[i].id+'">'+obj[i].name+'</option>').appendTo(category);
             //   alert(obj[i].id+'==='+obj[i].name);
            }
        });
    });






    });